package com.zr.spring.serialize;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.zr.spring.jedis.Person;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution {
    public static void main(String[] args) {

        HashMap<String, String> maps = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            Person person = new Person("zhangrui" + i, "1" + i, "男");
            maps.put(person.getName(), JSON.toJSONString(person));
        }

        //将map转换成jsonObject
        JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(maps));
        //将Map类型的itemInfo转换成json，再经JSONObject转换实现。

        //将jsonObj转换成Map
        //Map<String, String> itemMap = JSONObject.toJavaObject(itemJSONObj, Map.class);

        //System.out.println(JSONObject.toJSON(itemMap));
        List<Person> list = new ArrayList<>();
        maps.forEach((k, v) -> {
            Person person = JSON.parseObject(v, Person.class);
            list.add(person);
        });

        for (Person person : list) {
            System.out.println(JSONObject.toJSON(person));
        }

        //JOSN.parseObjet()方法同样可以转换

        //将List转换成JSONArray
        //JSONArray ja = JSONArray.parseArray(JSON.toJSONString(itemList));

        //json转成对象
        //List<Person> channelItemList  = JSON.parseArray(itemJson,ChannelItem.class);

        //将String转换成ArrayList 对象
        //ArrayList<HashMap<String,String>> paperAddOrDeleteQuestionList = JSON.parseObject(intelligentAddQuestionListStr,new TypeReference<ArrayList<HashMap<String,String>>>() {});

    }
}
